package com.jgc.stage01.关闭线程标志位;

/**
 * Created by Administrator on 2022/2/10.
 */
public class MyThread extends Thread {
    private boolean running = true;//这就是线程标志位 ，可以关闭线程
    @Override
    public void run() {
        while (running){
            System.out.println("线程正在运行");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public void stopRunning(){
        this.running = false;
    }

    public static void main(String[] args) throws InterruptedException {
        MyThread myThread = new MyThread();
        myThread.start();
        Thread.sleep(5000);
        myThread.stopRunning();
    }
}
